package cn.cvs.controller;

import cn.cvs.pojo.SysUser;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Controller
@RequestMapping(value = "/hello")
public class HelloController{

    @RequestMapping(value = "/hello")
    public ModelAndView hello(@RequestParam(required = false) String realName){
        System.out.println("你好，【"+realName+"】欢迎来到Spring MVC课堂");
        ModelAndView view = new ModelAndView();
        view.addObject("realName",realName);
        view.setViewName("hello");
        return view;
    }

    @RequestMapping(value = "/hello2")
    public String hello2(Model model, @RequestParam(value = "userName",required = false) String realName){
        System.out.println("你好，【"+realName+"】欢迎来到Spring MVC课堂");
        model.addAttribute("realName",realName);
        model.addAttribute(realName);
        SysUser user = new SysUser();
        user.setRealName(realName);
        model.addAttribute("currentUser",user);
        model.addAttribute(user);
        return "hello";
    }

    @RequestMapping(value = "/hello3")
    public String hello3(Map<String,Object> map, @RequestParam(value = "userName",required = false) String realName){
        System.out.println("你好，【"+realName+"】欢迎来到Spring MVC课堂");
        map.put("realName",realName);
        return "hello";
    }
}
